package com.GlobalPaint.app.ui.Home.Palette;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.GlobalPaint.app.Adapter.paletteDetailsAdapter;
import com.GlobalPaint.app.Base.DialogWaiting;
import com.GlobalPaint.app.R;
import com.GlobalPaint.app.bean.PaletteDetailsBean;
import com.GlobalPaint.app.bean.ReturnStatusResultEntity;
import com.GlobalPaint.app.utils.Constants;
import com.GlobalPaint.app.utils.DataManager;

import java.util.List;

public class PaletterDetailsActivity extends AppCompatActivity {
    private int fNodeId;
    private GridView gv_paletter_details;
    private Dialog dlgWaiting2;
    private PaletteDetailsBean paletteDetailsBean;
    private List<PaletteDetailsBean.DataBean> list;
    private ImageView iv_goback;
    private TextView tv_common_center;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_paletter_details);
        fNodeId=getIntent().getIntExtra("fNodeId",0);
        initView();
        getDetails();
    }

    private void getDetails() {
        String url= Constants.JASON_SERVICE_URL+"info/getInfo?fNodeId="+fNodeId;
        dlgWaiting2 = DialogWaiting.createDialogWaiting(PaletterDetailsActivity.this, "加载中......");
        dlgWaiting2.show();
        DataManager.getInst().getHttpRequestJsonClass(url, DataManager.userEntity.getCookie(), PaletteDetailsBean.class, new DataManager.Callback() {
            @Override
            public void onSuccess(Object o) {
                dlgWaiting2.cancel();
               paletteDetailsBean=(PaletteDetailsBean)o;
                if (paletteDetailsBean.getStatus() == 1){
                    if(paletteDetailsBean.getData() != null && paletteDetailsBean.getData().size()>0){
                        list=paletteDetailsBean.getData();
                        paletteDetailsAdapter adapter = new paletteDetailsAdapter(PaletterDetailsActivity.this,
                                R.layout.palette_details_gridview, list, list.size());
                        gv_paletter_details.setAdapter(adapter);
                    }
                    else {
                        Toast.makeText(PaletterDetailsActivity.this,"暂无数据",Toast.LENGTH_LONG).show();
                    }
                }
                else {
                    Toast.makeText(PaletterDetailsActivity.this,"暂无数据",Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onFailure(ReturnStatusResultEntity error) {
                Toast.makeText(PaletterDetailsActivity.this,"暂无数据",Toast.LENGTH_LONG).show();
            }
        });
    }
    private void initView() {
        gv_paletter_details = (GridView) findViewById(R.id.gv_paletter_details);
        iv_goback = (ImageView) findViewById(R.id.iv_goback);
        tv_common_center = (TextView) findViewById(R.id.tv_common_center);
        tv_common_center.setText("分类列表");
        iv_goback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
